﻿#region Copyright (c) 2000-2013 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{                                                                   }
{                                                                   }
{       Copyright (c) 2000-2013 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2013 Developer Express Inc.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UColor.Core.Helpers;
//using UColor.Core.DataClasses;
using UColor.Core;
using UColor.Core.Parts;
using System.Collections.ObjectModel;
using UColor.WPF.Helpers;
using System.Reflection;
using DevExpress.Utils;
using DevExpress.Xpf.Core;
using System.Threading;
using System.Windows;
using UColor.WPF.Internal;
using System.Windows.Controls;
using System.Windows.Media;
namespace UColor.WPF {
	public sealed class Base : BindingAndDisposable, IBackButton {
		
		Assembly demoAssembly;
		string productID;
		Assembly[] assemblies;
		string moduleName;
		LString title;
		
		public Base(Assembly demoAssembly, string moduleName) {
			this.demoAssembly = demoAssembly;
			this.moduleName = moduleName;
			assemblies = new Assembly[] { demoAssembly, typeof(Base).Assembly };
			ReadAttributes();
			DemoBaseControl = new BaseControl();
			DemoBaseControl.BackButtonClick += OnDemoBaseControlBackButtonClick;
			DemoBaseControl.BuyNowButtonClick += OnDemoBaseControlBuyNowButtonClick;
			//DemoBaseControl.Data.MainDataLoad += OnDemoBaseControlDataMainDataLoad;
			//DemoBaseControl.Data.ProductsLoad += OnDemoBaseControlDataProductsLoad;
			//DemoBaseControl.Data.MainProductLoad += OnDemoBaseControlDataMainProductLoad;
			//DemoBaseControl.Data.ProductsChanged += OnDemoBaseControlDataProductsChanged;
			DemoBaseControl.State = new BaseControlState() { Page =  BaseControlPage.ModulesPage };
            IntercallHelper.RegisterDemoBackButton(this);
			DemoBaseControl.State.ProductIDChanged += OnDemoBaseControlStateProductIDChanged;
			DemoBaseControl.State.PageChanged += OnDemoBaseControlStatePageChanged;
			OnDemoBaseControlStatePageChanged(DemoBaseControl.State, new ThePropertyChangedEventArgs<BaseControlPage>(BaseControlPage.MainPage, DemoBaseControl.State.Page));
		}
		public BaseControl DemoBaseControl { get; private set; }
		public LString Title {
			get { return title; }
			set { SetValue<LString>("Title", ref title, value); }
		}
		
		
		
		void OnFeaturedDemoSelected(object sender, EventArgs e) {
			
		}
		
		
		void ReadAttributes() {
			if(demoAssembly == null) return;
			object[] attrList = demoAssembly.GetCustomAttributes(false);
			foreach(Attribute attr in attrList) {
				if(attr is ProductIDAttribute) {
					this.productID = ((ProductIDAttribute)attr).ProductID;
				}
			}
		}
		void OnDemoBaseControlBackButtonClick(object sender, EventArgs e) {
			DemoBaseControl.State.Page =  BaseControlPage.ModulesPage;
		}
		void OnDemoBaseControlBuyNowButtonClick(object sender, EventArgs e) {
			//DocumentPresenter.OpenLink(DemoBaseControl.Data.MainData.BuyProductPage);
		}
		void OnDemoBaseControlStateProductIDChanged(object sender, ThePropertyChangedEventArgs<object> e) {
			UpdateBuyNowButtonVisibility();
		}
		void OnDemoBaseControlStatePageChanged(object sender, ThePropertyChangedEventArgs<BaseControlPage> e) {
			UpdateBuyNowButtonVisibility();
            bool v = true;// e.NewValue != BaseControlPage.ProductsPage;
            if (v == backButtonDesiredVisibility) return;
			backButtonDesiredVisibility = v;
			if(backButtonDesiredVisibilityChanged != null)
				backButtonDesiredVisibilityChanged(this, EventArgs.Empty);
		}
		void UpdateBuyNowButtonVisibility() {
			
		}
		#region IBackButton
		EventHandler backButtonDesiredVisibilityChanged;
		bool backButtonDesiredVisibility;
		bool IBackButton.ActualVisibility {
			get { return DemoBaseControl.State.ShowBackButton; }
			set { DemoBaseControl.State.ShowBackButton = value; }
		}
		event EventHandler IBackButton.Click {
			add { }
			remove { }
		}
		bool IBackButton.DesiredVisibility {
			get { return backButtonDesiredVisibility; }
		}
		event EventHandler IBackButton.DesiredVisibilityChanged {
			add { backButtonDesiredVisibilityChanged += value; }
			remove { backButtonDesiredVisibilityChanged -= value; }
		}
		void IBackButton.DoClick() {
			OnDemoBaseControlBackButtonClick(DemoBaseControl, EventArgs.Empty);
		}
		#endregion
		
	}
}
